package org.jerrymouse.financeApp;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.jerrymouse.agentContainer.Agent;

public class GoogleFinance extends Agent {
	/**
	 * 按月
	 * 
	 * @param no
	 * @param from
	 * @param to
	 * @return
	 */
	public List<Double> getCompanyFinance(String no, Date from, Date to) {
		List<Double> doubles = ((FinanceDB) getAgent(FinanceDB.class))
				.getCompanyFinance(makeCKey(no, from, to));
		if (doubles == null) {
			doubles = getCompanyFinanceFromWeb(no, from, to);
			((FinanceDB) getAgent(FinanceDB.class)).putCompanyFinance(makeCKey(
					no, from, to), doubles);
		}
		return doubles;
	}

	public List<Double> getTradeFinance(String no, Date from, Date to) {
		List<Double> doubles = ((FinanceDB) getAgent(FinanceDB.class))
				.getTradeFinance(makeTKey(no, from, to));
		if (doubles == null) {
			doubles = getTradeFinanceFromWeb(no, from, to);
			((FinanceDB) getAgent(FinanceDB.class)).putTradeFinance(makeTKey(
					no, from, to), doubles);
		}
		return doubles;
	}

	private String makeCKey(String no, Date from, Date to) {
		String key = "c" + no + "-" + from.getTime() + "-" + to.getTime();
		return key;
	}

	private String makeTKey(String no, Date from, Date to) {
		String key = "t" + no + "-" + from.getTime() + "-" + to.getTime();
		return key;
	}

	private List<Double> getCompanyFinanceFromWeb(String no, Date from, Date to) {
		List<Double> doubles = new ArrayList<Double>();
		doubles.add(new Double(100));
		return doubles;
	}

	private List<Double> getTradeFinanceFromWeb(String no, Date from, Date to) {
		List<Double> doubles = new ArrayList<Double>();
		doubles.add(new Double(100));
		return doubles;
	}


}
